import SEARCH_PARAMS from '@/config/search_params_config.js'
// 获取搜索参数 by shw
const getSearchParams = function (searchType) {
	const searchParamConfig = SEARCH_PARAMS[searchType]
	return (params) => {
		return {
			e: getParamsByConfig('eq', searchParamConfig, params),
			l: getParamsByConfig('link', searchParamConfig, params),
			custom: getParamsByConfig('custom', searchParamConfig, params),
			u: getFuzzyParams(searchParamConfig, params)
		}
	}
}
const getParamsByConfig = function (type, config, params) {
	const _params = {}
	if (config[type]) {
		config[type].forEach(item => {
			_params[item] = params[item]
		})
	}
	return _params
}
const getFuzzyParams = function (config, params) {
	const fuzzy = {}
	if (config.fuzzy) {
		config.fuzzy.forEach(item => {
			fuzzy[item.rule] = params[item.id]
		})
	}
	return fuzzy
}
export default {
	getSearchParams
}
